package org.one.stone.soup.grfxML;

import org.one.stone.soup.mjdb.data.field.DataLinker;
import org.one.stone.soup.mjdb.data.field.Field;
import org.one.stone.soup.mjdb.data.field.IntField;
import org.one.stone.soup.mjdb.data.field.LockException;
import org.one.stone.soup.xml.XmlElement;
  /*
 * Copyright 2000-2001 Wet-Wired.com Ltd.,
 * Portsmouth England
 * All rights reserved.
 */

/**
	*
	* @author Nik Cross
*/
public  class DataSize extends IntField implements IPrimative{
	public static String DEFAULT_ID="_Size";

	private TagModifier _modifier = TagModifier.SIZE_TYPE_SIZE;
public DataSize() {
	try{
		setId(_modifier.DEFAULT_ID,this);
	}
	catch(LockException le){} //Dummy catch
}
public DataSize( int size ) {
	super(size);
	try{
		setId(_modifier.DEFAULT_ID,this);
	}
	catch(LockException le){} //Dummy catch
}
public DataSize(TagModifier type) {
	_modifier = type;

	try{
		setId(_modifier.DEFAULT_ID,this);
	}
	catch(LockException le){} //Dummy catch
}
public DataSize( TagModifier type,int size ) {
	super(size);

	_modifier = type;

	try{
		setId(_modifier.DEFAULT_ID,this);
	}
	catch(LockException le){} //Dummy catch
}
public void buildFromgrfxML(XmlElement xml)
{
	buildFromgrfxML(xml,_modifier);
}
public void buildFromgrfxML(XmlElement xml,TagModifier type)
{
	_modifier = type;

	String attribName;
	String attribValue;

	for(int loop=0;loop<xml.getAttributeCount();loop++)
	{
		attribName = xml.getAttributeNameByIndex(loop);
		attribValue = xml.getAttributeValueByIndex(loop);

		if(attribName.equals(Token.ID))
		{
			if(attribValue!=null)
			{
				try{
					setId(attribValue,this);
				}
				catch(LockException le){} //Dummy catch
			}
		}
		else if(attribName.equals(_modifier.getAttributeAlias(Token.VALUE)))
		{
			try{
				setValue(Token.VALUE,attribValue,this);
			}
			catch(LockException le){}//dummy catch
		}
		else if(attribName.equals(_modifier.getAttributeAlias(Token.MIN_VALUE)))
		{
			try{
				setValue(Token.MIN_VALUE,attribValue,this);
			}
			catch(LockException le){}//dummy catch
		}
		else if(attribName.equals(_modifier.getAttributeAlias(Token.MAX_VALUE)))
		{
			try{
				setValue(Token.MAX_VALUE,attribValue,this);
			}
			catch(LockException le){}//dummy catch
		}
		else if( !NameHelper.isSystemName(attribName) )
		{
			GrfxMLException.warning( GrfxMLException.WARNING_UNRECOGNISED_ATTRIB_CODE ,new Object[]{attribName,Token.VALUE,""+xml.getStartLineNo()} );
		}
	}
}
public void copyFromgrfxML(XmlElement xml)
{
	copyFromgrfxML(xml,_modifier);
}
public void copyFromgrfxML(XmlElement xml,TagModifier type)
{
	_modifier = type;

	String attribName;
	String attribValue;

	for(int loop=0;loop<xml.getAttributeCount();loop++)
	{
		attribName = xml.getAttributeNameByIndex(loop);
		attribValue = xml.getAttributeValueByIndex(loop);

		if(attribName.equals(Token.ID))
		{
			// do nothing but not an error
		}
		else if(attribName.equals(_modifier.getAttributeAlias(Token.VALUE)))
		{
			try{
				setValue(Token.VALUE,attribValue,this);
			}
			catch(LockException le){}//dummy catch
		}
		else if(attribName.equals(_modifier.getAttributeAlias(Token.MIN_VALUE)))
		{
			try{
				setValue(Token.MIN_VALUE,attribValue,this);
			}
			catch(LockException le){}//dummy catch
		}
		else if(attribName.equals(_modifier.getAttributeAlias(Token.MAX_VALUE)))
		{
			try{
				setValue(Token.MAX_VALUE,attribValue,this);
			}
			catch(LockException le){}//dummy catch
		}
		else
		{
			GrfxMLException.warning( GrfxMLException.WARNING_UNRECOGNISED_ATTRIB_CODE ,new Object[]{attribName,Token.SIZE,""+xml.getStartLineNo()} );
		}
	}
}
public DataSize getClone() {
	return getClone(_modifier);
}
public DataSize getClone(String path) {
	return getClone(_modifier,path);
}
public DataSize getClone(TagModifier modifier) {

	_modifier = modifier;

	DataSize newSize = new DataSize();

	try{
		newSize.setValue(getValue(),this);
	}
	catch(LockException le){}//dummy catch

	newSize.setValueMin(getValueMin());
	newSize.setValueMax(getValueMax());

	return newSize;
}
public DataSize getClone(TagModifier modifier,String path) {

	_modifier = modifier;

	DataSize newSize = getClone();

	GrfxMLStoreProcessor.setCloneName( path,this,newSize );

/*	try{
		newSize.setValue(getValue(),this);
	}
	catch(LockException le){}//dummy catch

	newSize.setValueMin(getValueMin());
	newSize.setValueMax(getValueMax());*/

	return newSize;
}
public TagModifier getModifier() {
	return _modifier;
}
public void register(DataLinker store) {
	super.register(store);
}
public void replace(Field oldObj, Field newObj) {
}
public void replace(Field oldObj, Field newObj,boolean recursive) {
}
public void resetChanged() {

	super.resetChanged();


}
public String togrfxML(String name) {
	return IPrimativeHelper.togrfxML(this,name);
}
public String togrfxML(String name,TagModifier modifier) {
	return IPrimativeHelper.togrfxML(this,name,modifier);
}
public String togrfxML(IPrimative defaultField,String name) {
	return IPrimativeHelper.togrfxML(defaultField,this,name,null);
}
public String togrfxML(IPrimative defaultField,String name,TagModifier modifier) {
	return IPrimativeHelper.togrfxML(defaultField,this,name,modifier);
}

public String toString()
{
	return IPrimativeHelper.toString(this);
}
}
